<!DOCTYPE html>
<head>
	<title> ChomsPy :: DataAcquisitionDevice </title>
	<link rel="stylesheet" type="text/css" href="/lib/css/black-tie/jquery-ui-1.8.4.custom.css" />
	<link rel="stylesheet" type="text/css" href="/lib/css/dad.css" />
	<script type="text/javascript" src="/lib/js/main.js"></script>
	<script type="text/javascript" src="/lib/js/jquery/jquery-1.4.2.min.js"></script>
	<script type="text/javascript" src="/lib/js/jquery/jquery-ui-1.8.4.custom.min.js"></script>
	<script type="text/javascript">
		window.onload = function(){
			$("#dadDIV").dialog({
				title: "Pragmatic Console",
				autoOpen: false,
				modal: true,
				resizable: false,
				draggable: false,
				position: "center",
				open: function(){
					$("#pragmatic").width("50%");
					$("#data").width("80%");
					$("#data").height($("#dadDIV").height() - 100);
				},
				close: function(){
					// Disconnect from DAD, reset login...
					document.forms["dadForm"].reset();
					document.getElementById("pragmatic").value = "";
					document.getElementById("data").value = "";
				},
				buttons: {
					"Reset" : function(){
						// Clear Pragmatic and Data inputs.
						document.getElementById("pragmatic").value = "";
						document.getElementById("data").value = "";
					},
					"Execute" : function(){
						// Populate dadForm with Pragmatic, and Data (if applicable)
						// Process form, and show Results dialog.
						document.forms["dadForm"]["c"].value = document.getElementById("pragmatic").value;
						if (document.getElementById("data").value != ""){
							// Data is not blank...
							document.forms["dadForm"]["d"].value = document.getElementById("data").value;
						}else{
							// No data, make sure d field is cleared...
							document.forms["dadForm"]["d"].value = "";
						};
						document.getElementById("pragmatic").value = "";
						document.getElementById("data").value = "";
						executeCommand();
					}
				},
				width: $(document).width() - 200,
				height: $(document).height() - 200
			});
			$("#loginButton").button();
			$("#loginButton").click(function(){
				$("#dadDIV").dialog("open");
			});
		}
		
		function executeCommand(){
			var retVal = AjaxRequest("dadForm","superego/dad");
			if ("error" in retVal){
				alert(retVal["error"]);
			}else{
				document.getElementById("data").innerText = JSON.stringify(retVal);
			};
			return false;
		}
	</script>
</head>
<body>
<table id="parentTBL">
	<tr>
		<td id="parentHead">
			 { "ChomsPy" : [ "DataAcquisitionDevice",  "JSON Console" ] }
		</td>
	</tr>
	<tr>
		<td id="parentBody">
		<center>
		<div id="dadformdiv" class=" ui-corner-all">
			<form id="dadForm" method="post" action="#">
				<input type="hidden" name="c" value="">
				<input type="hidden" name="d" value="">
				<table id="loginTBL">
					<tbody>
					<tr>
						<td class="loginTD"> User : </td>
						<td class="loginTD"><input type="text" name="u" class="ui-corner-all"></td>
					</tr>
					<tr>
						<td class="loginTD"> Password : </td>
						<td class="loginTD"><input type="password" name="p" class="ui-corner-all"></td>
					</tr>
					</tbody>
				</table>
			</form>
			<div id="loginDIV">
				<button id="loginButton"> Connect </button>
			</div>
		</div>
		</center>
		</td>
	</tr>
	<tr>
		<td id="parentFoot">
			{ "&copy;" : [ "2010", "SnohomaNET" ] }
		</td>
	</tr>
</table>
<div id="dadDIV">
	Pragmatic : <input type="text" id="pragmatic" class="ui-corner-all"><br/>
	<textarea id="data" class="ui-corner-all"></textarea>
</div>
</body>
</html>
